package main

import (
	"fmt"
	"github.com/panjf2000/ants/v2"
	"os"
	"path"
	"runtime"
)

func main() {
	removeAll("C:\\Users\\admin\\AppData\\Local\\Temp")
	//ch := make(chan struct{})
	//defer close(ch)
	//
	//go func() {
	//	defer close(ch)
	//	ch <- struct{}{}
	//}()
	//i := 0
	//for range ch {
	//	i++
	//}
	//fmt.Printf("%d", i)
}
func removeAll(filePath string) {
	num := runtime.NumCPU()
	runtime.GOMAXPROCS(num - 2)
	fmt.Println("Cpu 核心数量：", num)
	fmt.Printf("Info: Start\n")
	//pool, err := ants.
	files := getAllFiles(filePath)
	FilesLen := len(files)
	fmt.Printf("共计%v个文件\n", FilesLen)

	for _, delPath := range files {
		fmt.Print(delPath + "\n")
		//os.RemoveAll(delPath)
		//go dodel(delPath)
	}
	//os.RemoveAll(filePath)
	fmt.Print(filePath + "\n")
	fmt.Println("删除完毕")
}

func getAllFiles(filePath string) []string {
	var files []string
	dir, _ := os.ReadDir(filePath)
	for _, d := range dir {
		if d.IsDir() {
			files = append(files, getAllFiles(path.Join([]string{filePath, d.Name()}...))...)
			files = append(files, path.Join([]string{filePath, d.Name()}...))
			continue
		}
		files = append(files, path.Join([]string{filePath, d.Name()}...))
	}
	return files
}
